华为机试题

您所在的位置:网站首页 python 删除字符串中出现次数最少的字符 华为机试题

华为机试题

2024-07-04 16:07| 来源: 网络整理| 查看: 265

描述

实现删除字符串中出现次数最少的字符,若出现次数最少的字符有多个,则把出现次数最少的字符都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。

数据范围:输入的字符串长度满足 1 \le n \le 20 \1≤n≤20  ,保证输入的字符串中仅出现小写字母

输入描述:

字符串只包含小写英文字母, 不考虑非法输入,输入的字符串长度小于等于20个字节。

输出描述:

删除字符串中出现次数最少的字符后的字符串。

示例1

输入:

aabcddd

复制输出:

aaddd #include #include #include #include #include #include #include #include #include #include #include #include void print(std::vector strVect) { for(int i = 0; i < strVect.size(); ++i) { std::cout second; count++; letterMap.erase(c); letterMap.insert(std::pair(c, count)); } } //2.找出次数最小的字母 std::multimap inMap; std::map::iterator iter = letterMap.begin(); while(iter != letterMap.end()) { inMap.insert(std::pair(iter->second, iter->first)); iter++; } // print(inMap); std::vector charVect; std::map::iterator iter1 = inMap.begin(); int frequence = iter1->first; while(iter1 != inMap.end()) { if(iter1->first > frequence) { break; } charVect.push_back(iter1->second); iter1++; } // print(charVect); std::string rtnStr; int index = 0; for(int j = 0; j < len; ++j) { //aabcdde for(int i = 0; i < charVect.size(); ++i) //b c e { char c = charVect[i]; if(str[j] == c) { str[j] = '-'; } } } for(int i = 0; i < strlen(str.c_str()); ++i) { if(str[i] != '-') { std::cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3